<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="./lib/react.development.js"></script>
    <script src="./lib/react-dom.development.js"></script>
    <script src="./lib/babel.min.js"></script>
</head>

<body>
    <div id="root"></div>
</body>
<script type="text/babel">
    const root = ReactDOM.createRoot(document.querySelector("#root"));
    class Student extends React.Component {
        
        say(){
            console.log('say')
            console.log('say this: ', this) // undefined
        }
        
        render() {
            console.log('render this: ', this)
            return (
                <>
                    <h3>学生信息</h3>
                    <p>name: 蔡永博</p>
                    <p>age:20</p>
                    <button onClick={this.say}>say</button>
                    
                    <button onClick={()=>{
                        // 调用者是window
                        console.log(this);// 当前组件的实例
                        this.say()

                    }}>想让事件回调中say方法的this，指向当前组件实例</button>
                </>
            )
        }
    }
    root.render((
        <div>
            <Student></Student>
            
            <hr />

            <h3>学校信息</h3>
            <p>学校名：尚硅谷</p>
            <p>学校地址：宏福科技园</p>
        </div>
    ))
</script>

</html>